package com.ap.core.email.webservice;

import com.ap.core.cxf.email.jaxb.managemessage.SendEmail1Request;
import com.ap.core.cxf.email.jaxb.managemessage.SendEmail1Response;
import com.ap.core.exception.BusinessFailureException;
import com.ap.core.message.service.CoreResponseInfo;
import com.ap.core.message.service.MessageProcessor;
import com.ap.wsdl.managemessageservice_1.Fault;
import com.ap.wsdl.managemessageservice_1.ManageMessage1PortType;

import javax.jws.WebParam;


/**
 * Web Service Implementation for sending email service {@link ManageMessage1PortType}
 */
public class ManageMessageServiceImpl<AI> extends BaseWSService<SendEmail1Request, SendEmail1Response> implements ManageMessage1PortType {

    private MessageProcessor<SendEmail1Request, SendEmail1Response, AI> messageProcessor;

    @Override
    public SendEmail1Response sendEmail1(@WebParam(partName = "sendEmail_1Request", name = "SendEmail_1Request", targetNamespace = "http://ap.com/xsd/managemessagedata_1") SendEmail1Request sendEmail1Request) throws Fault {
        CoreResponseInfo<SendEmail1Response, AI> coreResponseInfo = null;

        LOG.info("Starting processing in ap core at time: " + System.currentTimeMillis() + " for sending email");
        try {
            coreResponseInfo = messageProcessor.process(sendEmail1Request, new SendEmail1Response());
        } catch (BusinessFailureException e) {
            LOG.error("Exception occurred while sending email :", e);
            throw new Fault("Exception occurred during processing:", e);
        }
        LOG.info("Finishing processing in ap core at time: " + System.currentTimeMillis() + " for sending email");
        return coreResponseInfo.getResponse();
    }

    public void setMessageProcessor(MessageProcessor<SendEmail1Request, SendEmail1Response, AI> messageProcessor) {
        this.messageProcessor = messageProcessor;
    }
}
